import 'dart:async';

import 'package:flutter/material.dart';

import '../../bean/requesterror_bean.dart';
import '../../utils/widget/toast_widget.dart';

/// ### 请求错误统一处理
/// #### [context] 必填|上下文
/// #### [e] 必填|RequestErrorBean|错误内容（code：简码，msg：内容，data：数据）
void errorHandle(BuildContext context,RequestErrorBean e) {

  ToastWidget.closeToast();// 关闭所有BotToast类的提示窗

  switch (e.code) {
    case -1:
      ToastWidget.result(type: false, title: e.msg);
      break;
    case 4004:
      ToastWidget.result(type: false, title: '密钥失效请重新登入');
      Timer(Duration(seconds: 3),() => Navigator.pushNamedAndRemoveUntil(context, '/loginview', (_) => false));
      break;
    default:
      ToastWidget.result(type: false, title: e.msg);
  }
}